/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package boundaries;

import business.SearchingManager;
import entity.User;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.view.ViewScoped;

@ManagedBean
//SESSION 'COZ OTHERWISE IT WON'T WORK!!!
@SessionScoped
public class SearchView implements Serializable {

    private List<User> results;
    private User selectedUser;
    
    private String searchText;
    private String backPage;
    @EJB
    private SearchingManager sm;
    
    String text = String.valueOf(searchText);

   
    public void init() {
        if(searchText!=null){
            System.out.println("print search text:" + searchText);
            results = sm.search(searchText);
        }
    }
     
    public String searchToInvite(){
        System.out.println("print search text2:" + searchText);
        return "invitings?faces-redirect=true&searchText="+searchText;
    }

    public SearchView() {
    }
    
  
    public List<User> getResults() {
        return results;
    }

    public void setResults(List<User> results) {
        this.results = results;
    }

    public void setSelectedUser(User selectedUser) {
        System.out.println("setter of selected user");
        this.selectedUser = selectedUser;
    }
    

   

    public User getSelectedUser() {
        System.out.println("getter of selected user "/*selectedUser.getEmail()*/);
        return selectedUser;
    }

    public String getSearchText() {
        return searchText;
    }

    public void setSearchText(String searchText) {
        System.out.println(searchText);
      /*  if (searchText!=null){
            text = searchText;
        }*/
        this.searchText = searchText;
    }

    public String getBackPage() {
        return backPage;
    }

    public void setBackPage(String backPage) {
        this.backPage = backPage;
    }
    
    
    
    public String back(){
        searchText = null;
        results = new ArrayList<>();
        System.out.println(backPage);
        return backPage;
    }



}
